import { Result } from "@/utils/result";
import { Context, Next } from "koa";

const whitelistHost = ["www.yuque.com"];
const antitheftChain = async (ctx: Context, next: Next) => {
    const { referer } = ctx.request.header;
    if (referer) {
        const { hostname } = new URL(referer);
        if (!whitelistHost.includes(hostname)) ctx.status = 403;
    } else {
        ctx.status = 403;
    }
    await next();
};

export { antitheftChain };
